﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            MyList<string> list = new MyList<string>();
            Random r = new Random();
            //Stopwatch sw = new Stopwatch();
            //sw.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                list.Add(r.Next(0, 9).ToString());
            }


            
            //Console.WriteLine("Время создания:");
            //Console.WriteLine(sw.ElapsedMilliseconds);
  

            Console.WriteLine("Тест индексатора:");
            Console.WriteLine(list[1]);

            Console.WriteLine(list.first.next.data);

            Console.ReadLine();
        }
        public class MyListItem <Titem> 
        {
            public MyListItem<Titem> next;
            public Titem data;
        }
        public class MyList <Titem> 
        {

            public MyListItem<Titem> first;
            public MyListItem<Titem> last;
            public Titem this[int index]
            {
                get
                {

                    MyListItem<Titem> item = first;
                    for (int i = 0; i < index; i++)
                    {
                        item = item.next;
                    }
                    return item.data;
                 }
             
            }
            public void Remove(int n)
            {
                MyListItem<Titem> item = new MyListItem<Titem>();

               item.data = this [n - 1];
               item.next = item.next.next;
               
            }
 
            
          public void Add(Titem a)
            {
                var newitem = new MyListItem<Titem>();
                newitem.data=a;
                
                if (last == null)
                {
                    first = newitem;
                    last = newitem;
                }
                else
                {
                    last.next = newitem;
                    last = newitem;
                }
            }
        }

    }
}